#include <bits/stdc++.h>
#ifndef DEBUG
#define debug
#endif
using namespace std;

int main() {
  cin.tie(0)->sync_with_stdio(0);
  int n;
  int cas = 1;
  while (cin >> n && n) {
    vector<tuple<int, int, int>> a;
    for (int i = 0; i < n; i ++) {
      int x, y, z;
      cin >> x >> y >> z;
      a.emplace_back(x, y, z);
      a.emplace_back(x, z, y);
      a.emplace_back(y, x, z);
      a.emplace_back(y, z, x);
      a.emplace_back(z, x, y);
      a.emplace_back(z, y, x);
    }
    n *= 6;
    vector<vector<int>> graph(n);
    vector<int> indegree(n);
    for (int i = 0; i < n; i ++) {
      for (int j = 0; j < n; j ++) {
        if (get<0>(a[i]) > get<0>(a[j]) && get<1>(a[i]) > get<1>(a[j])) {
          graph[i].push_back(j);
          indegree[j] ++;
        }
      }
    }
    queue<int> q;
    vector<int> dp(n);
    for (int i = 0; i < n; i ++) {
      dp[i] = get<2>(a[i]);
      if (indegree[i] == 0) {
        q.push(i);
      }
    }
    while (!q.empty()) {
      int u = q.front();
      q.pop();
      for (auto v : graph[u]) {
        indegree[v] --;
        dp[v] = max(dp[v], dp[u] + get<2>(a[v]));
        if (indegree[v] == 0) {
          q.push(v);
        }
      }
    }
    cout << "Case " << cas ++ << ": maximum height = " << *max_element(dp.begin(), dp.end()) << endl;
  }
}